package com.dilidili.controller;

import com.dilidili.service.IUserService;
import com.domain.Fans;
import com.domain.User;
import com.github.pagehelper.PageInfo;
import com.util.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.security.NoSuchAlgorithmException;
import java.util.List;
import java.util.Map;

/**
 * @PackgeName: com.dilidili.controller
 * @ClassName: UserController
 * @Author: 零
 * Date: 2022/4/4 12:13
 * project name: spring-cloud-mybilibli
 * @Version: 用户请求层
 * @Description: 用户操作信息
 */
@RestControllerAdvice
@RequestMapping("/user")
public class UserController {

    /**
     * 用户业务层
     */
    @Autowired
    private IUserService userService;

    /**
     * 根据手机号查询用户
     * @param userTel
     * @return
     */
    @RequestMapping("/query")
    public List<Map<String,Object>> query(String userTel){
        return userService.query(userTel);
    }

    /**
     *
     * @param userTel
     * @return
     */
    @RequestMapping("userPhone")
    public User userPhone(String userTel){
        User user = userService.userPhone(userTel);
        System.out.println(user);
        return user;
    }

    /**
     * 根据手机号修改密码
     * @param userTel 手机号
     * @param userPassword 密码
     * @return 修改结果
     */
    @RequestMapping("amendPswd")
    public Integer amendPswd(String userTel,String userPassword){
        return userService.amendPswd(userTel,userPassword);
    }

    /**
     * 注册用户请求
     * @param user 用户对象
     * @return
     */
    @RequestMapping("saveUser")
    public Integer saveUser(User user){
        Integer result = userService.saveUser(user);
        System.out.println(result);
        if (result>0){
            return result;
        }else {
            System.out.println("添加失败");
        }
        return result;
    }

    /**
     * 用户请求查询关注人数
     * @param userId 用户id
     * @return 请求响应结果
     */
    @RequestMapping("fansByUserId")
    public Integer fansByUserId(Integer userId){
        return userService.fansByUserId(userId);
    }


    /**
     * 用户请求查询粉丝人数
     * @param userId 用户对象
     * @return
     */
    @RequestMapping("bean")
    public Integer beanByUserId(Integer userId){
        return userService.beanByUserId(userId);
    }

    /**
     * 用户请求修改头像
     * @param userId 用户对象
     * @param userImgsrc 用户对象
     * @return 响应结果
     */
    @RequestMapping("modification")
    public Integer modification(Integer userId,String userImgsrc){
        User user=new User();
        user.setUserId(userId);
        user.setUserImgsrc(userImgsrc);
        return userService.modification(user);
    }

    /**
     * 用户请求修改
     * @param user 用户对象
     * @return
     */
    @RequestMapping("revamp")
    public Integer revamp(User user){
        return userService.modification(user);
    }

    /**
     * 查询用户昵称
     * @param userNickname 用户昵称
     * @return 用户数据
     */

    @RequestMapping("userGetUserNickname")
    public  List<Map<String, Object>> userGetUserNickname(Integer userId,String userNickname){
        return userService.userGetUserNickname(userId,userNickname);
    }

    /**
     * 查询用户关注的人
     * @param userId
     * @param userNickname
     * @param pageNum
     * @param pageSize
     * @return queryFansBeanParticulars queryFansParticulars
     */
    @RequestMapping(value = "queryFansParticulars",method = RequestMethod.GET)
    public PageInfo<Map> queryFansParticulars(Integer userId,String userNickname,Integer pageNum, Integer pageSize) {
        PageInfo<Map> pageInfo = userService.queryFansParticulars(userId, userNickname, pageNum, pageSize);
        return pageInfo;
    }

    /**
     * 查询被关注的人
     * @param userId
     * @param userNickname
     * @param pageNum
     * @param pageSize
     * @return
     */
    @RequestMapping("queryFansBeanParticulars")
    PageInfo<User> queryFansBeanParticulars(Integer userId, String userNickname, Integer pageNum, Integer pageSize){
        return userService.queryFansBeanParticulars(userId,userNickname,pageNum,pageSize);
    }


    /**
     * 查询用户个人信息
     * @param userId
     * @return
     */
    @RequestMapping("findAll")
    public User findAll(Integer userId) {
        return userService.findAll(userId);
    }
}
